import { DataSet, Rule } from '@/types';

export const getMockRule = (source?: Record<string, unknown>): Rule => {
  const rule: Rule = {
    api_path: '/api/users',
    // preset_sences: [{ preset_id: 'preset_123', options: { type: 1 } }],
    condition: {
      context: {
        json_schema: {
          type: 'object',
          properties: {
            name: {
              type: 'string',
              minLength: 2,
            },
            age: {
              type: 'number',
              minimum: 18,
            },
          },
          required: ['name', 'age'],
        },
        report_raw_path: ['name', 'age'],
      },
    },
    validator: {
      response_body: {
        json_schema: {
          type: 'object',
          properties: {
            email: {
              type: 'string',
              pattern: '.+@bytedance.com$',
            },
          },
          required: ['email'],
        },
      },
    },
    info: {
      description: 'This rule checks if the user data is valid.',
    },
    ...source,
  };
  return JSON.parse(JSON.stringify(rule));
};

export const getMockDataSet = (): DataSet => {
  const dataSet: DataSet = {
    api_path: '/api/users',
    log_id: '123456',
    context: {
      name: '张三',
      age: 28,
    },
    response_body: {
      email: 'zhangsan.@bytedance.com',
    },
  };
  return JSON.parse(JSON.stringify(dataSet));
};

export const mockContextRule: Rule = {
  api_path: '/api/users',
  condition: {
    context: {
      json_schema: {
        type: 'object',
        properties: {
          name: {
            type: 'string',
            minLength: 2,
          },
          age: {
            type: 'number',
            minimum: 18,
          },
        },
        required: ['name', 'age'],
      },
    },
  },
  validator: {
    response_body: {
      json_schema: {
        type: 'object',
        properties: {
          email: {
            type: 'string',
            pattern: '.+@bytedance.com$',
          },
        },
        required: ['email'],
      },
    },
  },
  info: {
    description: 'This rule checks if the user data is valid.',
  },
};
